package com.dawnling.androidutils.ijkplayer;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.dawnling.androidutils.R;

public class IjkPlayerActivity extends AppCompatActivity implements PlayerManager.PlayerStateListener {

    String url = "rtmp://ip-phone.keytop.cn:9935/live/592581_172.19.2.123";
    private PlayerManager player = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ijk_player);

        initPlayer(url);
    }

    private void initPlayer(String path) {
        if (player != null) {
            if (player.isPlaying()) {
                player.stop();
            }
            player = null;
        }
        player = new PlayerManager(this);
        player.setFullScreenOnly(false);//是否全屏显示 false不全屏
        player.setScaleType(PlayerManager.SCALETYPE_WRAPCONTENT);
        player.playInFullScreen(false);//false竖屏  true横屏
        player.setPlayerStateListener(this);
        player.play(path);
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onError() {

    }

    @Override
    public void onLoading() {

    }

    @Override
    public void onPlay() {

    }

    @Override
    public void onPauseIjk() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (player != null) {
            player.stop();
            player = null;
        }
    }
}
